
'=======================================
' 执行所有测试 case
'=======================================
Private Sub test_PrimitiveStack_ALL_case()
    ' 基础功能测试
    test_PrimitiveStack_base
    ' peek 测试
    test_PrimitiveStack_peek
    ' clear 测试
    test_PrimitiveStack_clear
    ' Item 测试
    test_PrimitiveStack_Item
    ' 属性 MaxIndex 测试
    test_PrimitiveStack_MaxIndex
End Sub

' 基础功能测试
Private Sub test_PrimitiveStack_base()
    Dim stack As PrimitiveStack
    Set stack = New PrimitiveStack

    ' 空测试
    Debug.Assert stack.Count = 0
    Debug.Assert IsEmpty(stack.pop())
    Debug.Assert IsEmpty(stack.peek())

    ' 插入一个数据并弹出
    stack.push("v1")
    Debug.Assert stack.Count = 1
    Debug.Assert stack.peek() = "v1"
    Debug.Assert stack.pop() = "v1"

    Debug.Assert stack.Count = 0
    Debug.Assert IsEmpty(stack.pop())
    Debug.Assert IsEmpty(stack.peek())

    ' 插入两个数据并弹出
    stack.push("v1")
    stack.push("v2")
    Debug.Assert stack.Count = 2
    Debug.Assert stack.peek() = "v2"
    Debug.Assert stack.pop() = "v2"
    Debug.Assert stack.Count = 1
    Debug.Assert stack.peek() = "v1"
    Debug.Assert stack.pop() = "v1"

    Debug.Assert stack.Count = 0
    Debug.Assert IsEmpty(stack.pop())
    Debug.Assert IsEmpty(stack.peek())
End Sub

' peek 测试
Private Sub test_PrimitiveStack_peek()
    Dim stack As PrimitiveStack
    Set stack = New PrimitiveStack
    stack.push("v1")
    Debug.Assert stack.peek() = "v1"

    stack.push("v2")
    Debug.Assert stack.peek() = "v2"
End Sub

' clear 测试
Private Sub test_PrimitiveStack_clear()
    Dim stack As PrimitiveStack
    Set stack = New PrimitiveStack
    stack.push("v1")
    stack.push("v2")
    stack.push("v3")
    Debug.Assert stack.Count = 3

    stack.clear
    Debug.Assert stack.Count = 0

    stack.push("v1")
    stack.push("v2")
    stack.push("v3")
    Debug.Assert stack.Count = 3

    Debug.Assert stack.pop() = "v3"
    Debug.Assert stack.Count = 2
    Debug.Assert stack.pop() = "v2"
    Debug.Assert stack.Count = 1
    Debug.Assert stack.pop() = "v1"
    Debug.Assert stack.Count = 0
    Debug.Assert IsEmpty(stack.pop())
    Debug.Assert stack.Count = 0

End Sub

' Item 测试
Private Sub test_PrimitiveStack_Item()
    Dim stack As PrimitiveStack
    Set stack = New PrimitiveStack

    stack.push "v1"
    stack.push "v2"
    stack.push "v3"

    Debug.Assert stack.Item(0) = "v1"
    Debug.Assert stack.Item(1) = "v2"
    Debug.Assert stack.Item(stack.Count() - 1) = "v3"
End Sub

' 属性 MaxIndex 测试
Private Sub test_PrimitiveStack_MaxIndex()
    Dim stack As PrimitiveStack
    Set stack = New PrimitiveStack

    Debug.Assert stack.MaxIndex = -1

    stack.push "v1"
    Debug.Assert stack.MaxIndex = 0

    stack.push "v2"
    Debug.Assert stack.MaxIndex = 1
End Sub